using System;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
    /**
     * Classname : Nguoidung
     * Version information :1.0
     * Date  :26-09-2006
     * Copyright notice : 
     */

    public class DATrangThaiGoi : DbObject
    {
        protected SqlConnection connec;

        public DATrangThaiGoi(SqlConnection Connection)
        {
            connec = Connection;
        }
        // Kiem tra mat khau nguoi dung
        public DataSet LayDanhSachTrangThaiGoi()
        {
            // create the parameter
            DataSet dsTrangThaiGoi = RunProcedure("sp_TrangThaiGois_loadLayDanhSachTrangThaiGoi", "TB_TrangThaiGoi", connec);
            for (int i = 0; i < dsTrangThaiGoi.Tables[0].Rows.Count; i++)
            {
                dsTrangThaiGoi.Tables[0].Rows[i]["Seq"] = (i + 1).ToString();
            }
            return dsTrangThaiGoi;
        }
        /// <summary>
        ///  Created by LinhDH 2012.08.30
        /// </summary>
        /// <param name="ip_str_yn"></param>
        /// <returns></returns>
        public DataSet LayDanhSachTrangThaiGoiByTiepTucYN(string ip_str_yn)
        {
            // create the parameter
            SqlParameter[] parameters = { 
                                            new SqlParameter("@TiepTuc_YN", SqlDbType.VarChar, 2)
                                        };
            parameters[0].Value = ip_str_yn;
            DataSet dsTrangThaiGoi = RunProcedure("sp_TrangThaiGois_loadLayDanhSachTrangThaiGoiByTiepTucYN", parameters, "TB_TrangThaiGoi", connec);
            for (int i = 0; i < dsTrangThaiGoi.Tables[0].Rows.Count; i++)
            {
                dsTrangThaiGoi.Tables[0].Rows[i]["Seq"] = (i + 1).ToString();
            }
            return dsTrangThaiGoi;
        }
		// return only the record with the specified ID!!!!!!!!!!!
		public DataRow loadTrangThaiGoiID(int TrangThaiGoiId)
		{
			// create the parameter
			SqlParameter[] parameters = { new SqlParameter("@TrangThaiGoiId", SqlDbType.Int, 4) };
			parameters[0].Value = TrangThaiGoiId;

            using (DataSet categorys = RunProcedure("sp_TrangThaiGois_loadTrangThaiGoiID", parameters, "TB_TrangThaiGoi", connec))
			{
				return categorys.Tables[0].Rows[0];
			}
		}	

		// update the properties of the specified Categorys
		// Sua noi dung ban ghi hien hanh
		public int updateTrangThaiGoi(int TrangThaiGoiId, string TrangThaiGoiName, string ip_str_tiep_tuc_yn)
		{
			int numAffected;
			// create the parameters
			SqlParameter[] parameters = { 	    new SqlParameter("@TrangThaiGoiId", SqlDbType.Int, 4),
											    new SqlParameter("@TrangThaiGoiName", SqlDbType.NVarChar, 128),
                                                new SqlParameter("@TiepTucYN", SqlDbType.VarChar, 2)
										};
			// set the values
			parameters[0].Value = TrangThaiGoiId;
            parameters[1].Value = TrangThaiGoiName.Trim();
            parameters[2].Value = ip_str_tiep_tuc_yn;
			// run the procedure
            RunProcedure("sp_TrangThaiGois_updateTrangThaiGoi", parameters, out numAffected, connec);

			return numAffected;
		}

		// add a new question
		// Them ban ghi hien hanh
		public int insertTrangThaiGoi(string TrangThaiGoiName, int LanguageID, string ip_str_tiep_tuc_yn)
		{
			int numAffected;
			// create the parameters
            SqlParameter[] parameters =  {	    new SqlParameter("@TrangThaiGoiName", SqlDbType.NVarChar, 128),
											    new SqlParameter("@TrangThaiGoiId", SqlDbType.Int ,4),
                                                new SqlParameter("@TiepTucYN", SqlDbType.VarChar ,2)
										 };	
			// set the values
			parameters[0].Value = TrangThaiGoiName.Trim();
			parameters[1].Direction = ParameterDirection.Output;
            parameters[2].Value = ip_str_tiep_tuc_yn;
		
			// run the procedure
            RunProcedure("sp_TrangThaiGois_insertTrangThaiGoi", parameters, out numAffected, connec);

			return (int)parameters[1].Value;
		}
		// Xoa Role
		public int removeTrangThaiGoi(int TrangThaiGoiID)
		{
			int numAffected;
			// create the parameters
			SqlParameter[] parameters = {	new SqlParameter("@TrangThaiGoiID", SqlDbType.Int)	};
			parameters[0].Value = TrangThaiGoiID;			
			// run the procedure
            try
            {
                RunProcedure("sp_TrangThaiGois_removeTrangThaiGois", parameters, out numAffected, connec);
            }
            catch
            {
                numAffected = 0;
            }
			return numAffected;			
		}
    }
}